﻿Public Class xtf_documentoCambioPrecio
    Public WithEvents dtt_DataTable As New DataTable

    Public Sub IniciarLista(ByRef documento As cls_documento_)
        Try
            gdc_general.BeginUpdate()
            gdc_general.DataSource = dtt_DataTable
            'ulg_Lista.DisplayLayout.GroupByBox.Style = Infragistics.Win.UltraWinGrid.GroupByBoxStyle.Full

            'Creacion y carga de Cuentas
            dtt_DataTable.Columns.Add("Check")
            dtt_DataTable.Columns.Add("Identificador (ID)")
            dtt_DataTable.Columns.Add("Nombre")
            dtt_DataTable.Columns.Add("Valor", GetType(Decimal))
            dtt_DataTable.Columns.Add("Unidad")
            dtt_DataTable.Columns.Add("Moneda")

            gdv_general.PopulateColumns(dtt_DataTable)
            gdv_general.Columns(0).ColumnEdit = New DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit
            gdv_general.Columns(0).OptionsColumn.AllowEdit = True
            gdv_general.Columns(1).Visible = False

            gdv_general.Columns(1).OptionsColumn.AllowEdit = False
            gdv_general.Columns(2).OptionsColumn.AllowEdit = False
            gdv_general.Columns(3).OptionsColumn.AllowEdit = False
            gdv_general.Columns(4).OptionsColumn.AllowEdit = False
            gdv_general.Columns(5).OptionsColumn.AllowEdit = False

            Dim temp_proveedor As New cls_proveedor_
            temp_proveedor.BuscarXidtercero(documento.idtercero)
            For Each documentodetalle As cls_documentodetalle_ In documento.documentodetalle_.Items
                If documentodetalle.idarticulo <> 0 Then
                    If documentodetalle.valorfinal <> documentodetalle.articulo.costo(cls_articulocomposicionarticulo_.enu_segunvalor.proveedor, temp_proveedor.idproveedor) Then
                        AgregarItem(documentodetalle, documento)
                    End If
                End If
            Next
            'ulg_Lista.DataBind()
            gdc_general.EndUpdate()
            gdv_general.BestFitColumns()
        Catch ex As Exception
            'Dim frmError As New frm_ErrorManager(ex.Message)
        End Try
    End Sub

    Public Function AgregarItem(ByRef documentodetalle As cls_documentodetalle_, ByRef documento As cls_documento_) As DataRow
        Dim Row As DataRow = dtt_DataTable.NewRow
        Row("Check") = True
        Row("Identificador (ID)") = documentodetalle.iddocumentodetalle
        Row("Nombre") = documentodetalle.nombre
        Row("Valor") = documentodetalle.valorfinal
        Row("Unidad") = documentodetalle.unidaddetalle.ToString
        Row("Moneda") = documento.moneda.simbolo
        dtt_DataTable.Rows.Add(Row)
        'ulg_Lista.Rows(ulg_Lista.Rows.Count - 1).Height = 19
        Return Row
    End Function
End Class